//index.js
//获取应用实例
var api = require('../../utils/api.js');

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  getUserInfo: function (e) {
    console.log(e.detail);
    var user_info = e.detail.userInfo;
    if (user_info) {
       wx.setStorageSync('hasGetUserInfo', 1);
       wx.setStorageSync('user_info', user_info);
       
      api.get({
        url: 'Login/addUser',
        data: {
          'encrypted_data' : e.detail.encryptedData,
          'iv'             : e.detail.iv,
          'raw_data'       : e.detail.rawData,
          'signature'      : e.detail.signature
        },
        success: res => {
            wx.redirectTo({
              url: '/pages/home/home',
            })
          
        },
      });
    } else {
      wx.showModal({
        title: '学习失败',
        showCancel: false,
        content: '请允许授权',
        success: function (res) {

        }
      })
    }

  }
})
